<?php
// ***************************************************************************** 
//  Copyright 2007 AMC - Websource
//  Glenview, Illinois 
// 
//  File:           project.php 
//  Author:         Mickey Freeman (mfreeman@connect2amc.com)
//  Function:       Class definition for project data, extends app_object
// 
//  Created: 12/03/2007
//  Version: 1.0 
// 
//  Modified: 
//    
// 
// ******************************************************************************

class project extends app_object
{
	/**
	 * Constructor, loads class defaults
	 *
	 * @return project
	 */
	function project()
	{
		$fields = array(
		        'project_name',
		        'project_url',
		        'project_add_date',
		        'project_status'
		);
		
		$table = PROJECT_TABLE;
		$id_field = 'project_id';
		parent::app_object($fields, $table, $id_field);
		
	}
	
	function validate_project()
	{
	$errors  = array();
	if($this->values['project_name']=='')
	  {
		$errors[] ='You must specify project name';
		
	  }	
	if($this->values['project_url']=='')
	  {
		$errors[] ='You must specify project url';
		
	  }	
	 return $errors;
    }
	function save()
	{
		$this->values[project_add_date]  = time();
		$this->values[project_status]    = 1;
		parent::save();
    }
    
	/**
	 * Retrieves all project type records from the database and returns them as an associative array
	 * 
	 * @return array
	 */
	function get_all_project()
	{
		$sql = "SELECT * FROM " . PROJECT_TABLE . " where project_status=1 ORDER BY project_name";
		
		$result = app_data::mysql_query($sql);
		
	
		
		return $result;
	}
	function get_project_list()
	{
		$menu_arr  = array();
		$sql       = "SELECT * FROM " . PROJECT_TABLE . " where 	project_status=1 ORDER BY project_name";
		
		$result    = app_data::mysql_query($sql);
		if($result)
		{
			while($row = mysql_fetch_assoc($result))
			{
				$menu_arr[$row[project_id]] =  $row[project_name];
				
			}
			return $menu_arr;
			
		}
		
	
		
		return $result;
	}
	function get_project($pro_id = '')
	{
		if($pro_id!='')
		{
			$sql_sub = " Where project_id= ".$pro_id;
		}
		$sql          = "SELECT * FROM " . PROJECT_TABLE . $sql_sub;
		
		$result       = app_data::mysql_query($sql);
		$result_arr   = mysql_fetch_assoc($result);  
		return $result_arr;
	}
}